var select2;
var toolbar1 =

    '<div id="toolbar" class="btn-group">\n' +
    '        <button id="btn_delete" type="button" class="btn btn-danger btn-xs" onclick="deletes()"><i class="fa fa-trash-o"></i>删除</button>' +
    ' </div>'
$(function () {
    select2 = $('.select2').select2()
    var columns = [
        {
            field: 'ck',
            checkbox: true
        },
        {
            field: 'uid',
            title: '用户'
        },
        {
            field: 'orderNum',
            title: '订单号',
            width: 100,
        },
        {
            field: 'info',
            title: '商品', //
            formatter: function (info) {
                let html = ''
                info.map(i => {
                    html = html +
                        '<div style="display: flex;flex-direction: row;padding-bottom: 10px">' +
                        '<image style="height: 40px;width: 40px" src=' + i.pictures + '></image>' +
                        '<div style="display: flex;flex-direction: column;justify-content: space-between;margin-left: 10px">' +
                        '<div>' + i.name + '</div>' +
                        '<div style="display: flex;flex-direction: row">￥' + i.price + '<p style="padding-left: 5px;padding-right: 5px">x</p>' + i.number + '</div>' +
                        '</div>' +
                        '</div>'
                })
                return html;
            }
        },
        {
            field: 'number',
            title: '商品数目',
        },
        {
            field: 'payPrice',
            title: '支付金额',
        },
        {
            field: 'status',
            title: '支付状态',
            formatter: function (value, row, index) {
                if (value == 0) {
                    return '未支付'
                }
                if (value == 1) {
                    return '已支付'
                }
            }
        },
        {
            field: 'payTime',
            title: '支付时间',
        },
        {
            field: 'userName',
            title: '收货人',
            formatter: function (value, row, index) {
                return '<div style="display: flex;flex-direction: column;w">' +
                    '<p>' + value + '</p>' +
                    '<p>' + row.telNumber + '</p>' +
                    '<p>' + row.aid + '</p>' +
                    '</div>'
            }
        },
        {
            field: 'createDate',
            title: '创建时间',
        },
        {
            field: 'id',
            title: '操作',
            formatter: function (value, row, index) {
                return '<button type="button" class="btn btn-danger  btn-xs" onclick="deletes(\'' + value + '\')" style="margin-left: 10px;"><i class="fa fa-trash-o"></i> 删除</button>';
            }
        }
    ]
    createBootstrapTable($("#table"), '/shop/order/findPage', columns, true, toolbar1, 'server')
})

var add_form;
var loading;


function deletes(id) {
    var ids = [];
    if (id != undefined) {
        ids.push(id)
    } else {
        $.each($('tbody input:checkbox:checked'), function () {
            ids.push($(this).parents('tr').data('uniqueid'));
        });
    }
    if (ids.length < 1) {
        layer.msg("最少请选择一条数据！")
        return;
    }
    var data = {
        ids: ids.toString()
    }

    layer.confirm('确定删除吗？', {
        title: '提示', btn: ['取消', '确定'] //按钮
    }, function () {
        layer.close(layer.index)
    }, function () {
        request('/shop/order/delete', 1, data, function (res) {
            if (res.code == 0) {
                layer.msg("删除成功", {time: 1000}, function () {
                    onLoads($("#href").val())
                })
            } else {
                layer.msg(res.msg, {time: 1000})
            }
        }, function (error) {
            layer.msg("系统异常！")
        })
    });
}

function resetForm() {
    $("#searchForm")[0].reset();
    $("#table").bootstrapTable('refresh');
}

// 查询
function searchForm(tableId, url, FormId) {
    var data = serializeObject("searchForm");
    var opt = {
        url: '/shop/order/findPage',
        silent: true,
        query: data
    };
    $("#table").bootstrapTable('refresh', opt);
}


